//
//  CLBasicView.m
//  MasonryTest
//
//  Created by Charles on 16/9/23.
//  Copyright © 2016年 Charles. All rights reserved.
//

#import "CLBasicView.h"

@implementation CLBasicView{
    UIView * greenView;
    UIView * redView;
    UIView * blueView;
}

- (void)dealloc{
    NSLog(@"CLBasicView dealloc!");
}
- (instancetype)init{
    if (self = [super init]) {
        [self makeView];
    }
    return self;
}

- (void)makeView{
    
    greenView = [[UIView alloc]init];
    greenView.backgroundColor = [UIColor greenColor];
    greenView.layer.borderColor = [UIColor blackColor].CGColor;
    greenView.layer.borderWidth = 2;
    [self addSubview:greenView];
    
    redView = [[UIView alloc]init];
    redView.backgroundColor = [UIColor redColor];
    redView.layer.borderColor = [UIColor blackColor].CGColor;
    redView.layer.borderWidth = 2;
    [self addSubview:redView];

    blueView = [[UIView alloc]init];
    blueView.backgroundColor = [UIColor blueColor];
    blueView.layer.borderColor = [UIColor blackColor].CGColor;
    blueView.layer.borderWidth = 2;
    [self addSubview:blueView];
    
    [self addConstraints];
    
}
- (void)addConstraints{
    UIView * superview = self;
    int padding = 10;
    [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.greaterThanOrEqualTo(superview.top).offset(padding);
        make.left.equalTo(superview.left).offset(padding);
        make.bottom.equalTo(blueView.top).offset(-padding);
        make.right.equalTo(redView.left).offset(-padding);
        make.width.equalTo(redView.width);
        
        make.height.equalTo(redView.height);
        make.height.equalTo(blueView.height);

    }];
    
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(superview.mas_top).with.offset(padding); //with with
        make.left.equalTo(greenView.mas_right).offset(padding); //without with
        make.bottom.equalTo(blueView.mas_top).offset(-padding);
        make.right.equalTo(superview.mas_right).offset(-padding);
        make.width.equalTo(greenView.mas_width);
        
        make.height.equalTo(@[greenView, blueView]); //can pass array of views
    }];
    
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(greenView.mas_bottom).offset(padding);
        make.left.equalTo(superview.mas_left).offset(padding);
        make.bottom.equalTo(superview.mas_bottom).offset(-padding);
        make.right.equalTo(superview.mas_right).offset(-padding);
        make.height.equalTo(@[greenView.mas_height, redView.mas_height]); //can pass array of attributes
    }];
    
}

@end
